package edu.washington.ling.syntric.io;

import java.io.IOException;

import edu.washington.ling.syntric.struct.error.InvalidValueException;

public abstract class TreeFileWriter {
	private String path;
	
	public TreeFileWriter(String path) throws IOException {
		this.path = path;
	}
	
	public static TreeFileWriter newWriter(String path, String format) throws IOException, InvalidValueException {
		TreeFileWriter tfw;
		if (format.equals("flat"))
			tfw = new TreeFileWriterFlat(path);
		else if (format.equals("sgml"))
			tfw = new TreeFileWriterSGML(path);
		else if (format.equals("latex"))
			tfw = new TreeFileWriterLaTeX(path);
		else {
			String[] possibleFormats = {"flat", "sgml", "latex"};
			throw new InvalidValueException("Specified tree format unknown.", format, possibleFormats);
		}
		return tfw;
	}
	public String getPath() {
		return path;
	}

	public abstract void close();
	public abstract void writeTreeRep(TreeRepresentation tr, String id);
}
